package com.dzt.androidframework.database.taskdetail;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;

import com.dzt.androidframework.R;
import com.dzt.androidframework.activity.ActivityTitle;
import com.dzt.androidframework.database.tasks.TasksLocalDataSource;

/**
 * 显示任务详细信息
 */
public class TaskDetailActivity extends ActivityTitle {

	public static final String EXTRA_TASK_ID = "TASK_ID";
	private TaskDetailPresenter taskDetailPresenter;
	private TaskDetailFragment taskDetailFragment;

	@Override
	protected int getLayoutId() {
		return R.layout.activity_task_detail;
	}

	@Override
	protected void initParams() {
		setTitleView(R.string.task_detail);
		// Get the requested task id
		String taskId = getIntent().getStringExtra(EXTRA_TASK_ID);
		FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		taskDetailFragment = TaskDetailFragment.newInstance(taskId);
		ft.add(R.id.contentFrame, taskDetailFragment);
		ft.commitAllowingStateLoss();

		// Create the presenter
		TasksLocalDataSource localDataSource = TasksLocalDataSource.getInstance();
		taskDetailPresenter = new TaskDetailPresenter(taskId, localDataSource,
				taskDetailFragment);
		taskDetailFragment.setPresenter(taskDetailPresenter);
	}

	@Override
	protected void initData(Bundle savedInstanceState) {

	}

	@Override
	protected String[] initPermissions() {
		return new String[0];
	}

	@Override
	public boolean onSupportNavigateUp() {
		onBackPressed();
		return true;
	}
}
